CURDIR := $(notdir $(shell pwd))
LIB_NAME?=lib$(CURDIR)

LIB_PATH=../build/libs

SHARE_LIB=$(LIB_PATH)/$(LIB_NAME).so
STATIC_LIB=$(LIB_PATH)/$(LIB_NAME).a

INCL := -I./include/
LIB:= -L. -lpthread

CFLAGS+=$(INCL) $(LIB) -shared -fPIC

SOURCE_PATH=.
BUILD_PATH=.

SOURCE := $(wildcard $(SOURCE_PATH)/*.c)
OBJS := $(patsubst %.c, $(BUILD_PATH)/%.o, $(notdir $(SOURCE)))


all:$(SHARE_LIB) $(STATIC_LIB)

$(SHARE_LIB):$(OBJS)
	echo $(SOURCE)
	$(CC) $(CFLAGS) $(OBJS) -o $(SHARE_LIB) 

$(STATIC_LIB):$(OBJS)
# ranlib 相当于 ar -s
	ar cr $(STATIC_LIB) $(OBJS)
	ranlib $(STATIC_LIB)

#生成二进制文件(*.o)	
$(OBJS): $(BUILD_PATH)/%.o:$(SOURCE_PATH)/%.c %.h
	$(CC) -c $(CFLAGS) $< -o $@

clean:
	rm -rf *.o *.a *.so

.PHONY: all clean